package com.lemon.system.api.factory;

import com.lemon.common.core.domain.Result;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.system.api.RemoteUserService;
import com.lemon.system.api.domain.BiUser;
import com.lemon.system.api.domain.BiUserThirdBind;
import com.lemon.system.api.domain.SysUser;
import com.lemon.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 * 
 * @author huangpeng
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public Result<LoginUser> getUserInfo(String username, String source)
            {
                return Result.error("通过用户名获取后台用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return Result.error("注册后台用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<LoginUser> getInfoByUserCode(String username, String source) {
                return Result.error("通过用户编码获取前台用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<LoginUser> getInfoByEmail(String email, String source) {
                return Result.error("通过邮箱获取前台用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<LoginUser> getInfoByPhone(String phone, String source) {
                return Result.error("通过手机号码获取前台用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<BiUser> registerBaseUserInfo(BiUser baseUser, String source) {
                return Result.error("注册前台用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<LoginUser> getInfoByOriginUid(String originUid, String thirdSource, String source) {
                return Result.error("通过资料来源平台的当前用户唯一uid获取前台用户失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult insertThirdBind(BiUserThirdBind model, String source) {
                return AjaxResult.error("绑定第三方账号失败:" + throwable.getMessage());
            }
        };
    }
}
